const { Container, MayBe } = require("./functor.js")
const fp = require("lodash/fp")

let maybe = MayBe.of([5, 6, 1])

let ex1 = () => {
  return maybe.map(fp.curry(fp.map)(fp.curry(fp.add)(1)))
}

let xs = Container.of(['do', 'ray', 'me', 'fa', 'so', 'la', 'ti', 'do'])

let ex2 = () => {
  return xs.map(fp.first)
}

let safeProp = fp.curry(function(x, o) {
  return MayBe.of(o[x])
})
let user = { id: 2, name: 'Albert' }

let ex3 = () => {
  return safeProp('name')(user).map(fp.first)
}

// let ex4 = function(n) {
//   if (n) {
//     return parseInt(n)
//   }
// }

let ex4 = (n) => {
  return MayBe.of(n).map(parseInt)
}

console.log('xx2..', ex4(-11.23))


// const a = new Container('aa')
// a.map((val) => {
//   console.log('xx', val)
//   return 'bb'
// }).map(val => {
//   console.log('xx1', val)
// })